﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLogic.DTO;
using BusinessLogic.Repository_Logic.Interfaces;

namespace TestSystem.Controllers.Administrator
{
    public class CandidateController : Controller
    {
        private ICandidateRepositoryLogic _candidateRepositoryLogic;

        public CandidateController(ICandidateRepositoryLogic candidateRepositoryLogic)
        {
            _candidateRepositoryLogic = candidateRepositoryLogic;
        }

        public ActionResult Index()
        {
            return View(_candidateRepositoryLogic.GetCandidates());
        }

        public ActionResult AddCandidate()
        {
            return View(_candidateRepositoryLogic.GetEmptyCandidateDTO());
        }

        [HttpPost]
        public ActionResult AvailablePositionsForUser(int UserId)
        {
            var Positions = _candidateRepositoryLogic.GetAvaiablePositionForUser(UserId);
            return Json(Positions);
        }

        [HttpPost]
        public string Save(CandidateDTO candidateDto)
        {
            _candidateRepositoryLogic.AddCandidate(candidateDto);  
            return Url.Action("Index");
        }

        [HttpPost]
        public ActionResult Remove(int id)
        {
            _candidateRepositoryLogic.RemoveCandidate(id);

            var results = new
            {
                Message = "Pomyślnie usunięto kandydata.",
                DeleteId = id,
                ItemCount = _candidateRepositoryLogic.GetCandidatesAmount()
            };
            return Json(results);
        }
    }
}
